class Solution {
public:
    void reverse_String(string& s, int begin, int end)
    {
        while (begin < end)
        {
            swap(s[begin], s[end]);
            begin++;
            end--;
        }
    }
    string reverseWords(string s) {
        int i = 0;
        while (i < s.size())
        {
            while (s[i] == ' ')
            {
                i++;
            }
            int start = i;
            while (i < s.size() && s[i] != ' ')
            {
                i++;
            }
            int end = i;
            reverse_String(s, start, end - 1);
        }
        return s;
    }
};